#define  _CRT_SECURE_NO_WARNINGS
#include <vector>
using namespace std;
class Solution {
public:
    int LastRemaining_Solution(int n, int m) {
        // write code here
        vector<int> v(n, 0);
        for (int i = 0; i < n; i++)
            v[i] = i;
        int index = 0;
        while (v.size() > 1)
        {
            index = (index + (m - 1) % v.size()) % v.size();
            v.erase(v.begin() + index);
        }
        return v[0];
    }
};

int main()
{
    Solution().LastRemaining_Solution(2, 3);
}